#!/bin/bash

echo "========================================"
echo "小智医疗系统启动脚本"
echo "========================================"
echo

echo "正在检查环境..."

# 检查Java环境
if ! command -v java &> /dev/null; then
    echo "错误: 未检测到Java环境，请先安装Java 17或更高版本"
    exit 1
fi

# 检查Maven环境
if ! command -v mvn &> /dev/null; then
    echo "错误: 未检测到Maven环境，请先安装Maven"
    exit 1
fi

# 检查Node.js环境
if ! command -v node &> /dev/null; then
    echo "错误: 未检测到Node.js环境，请先安装Node.js"
    exit 1
fi

echo "环境检查完成！"
echo

echo "正在启动后端服务..."
gnome-terminal --title="小智医疗后端" -- bash -c "cd $(pwd) && mvn spring-boot:run; exec bash" &

echo "等待后端服务启动..."
sleep 10

echo "正在启动前端服务..."
gnome-terminal --title="小智医疗前端" -- bash -c "cd $(pwd)/xiaozhi-ui && npm run dev; exec bash" &

echo
echo "========================================"
echo "系统启动完成！"
echo "========================================"
echo "后端服务: http://localhost:8080"
echo "前端服务: http://localhost:5173"
echo "API文档: http://localhost:8080/doc.html"
echo "========================================"
echo
echo "请确保以下服务已启动："
echo "1. MySQL数据库 (端口: 3306)"
echo "2. MongoDB数据库 (端口: 27017)"
echo
echo "请确保以下环境变量已配置："
echo "1. DASH_SCOPE_API_KEY (阿里云百炼API密钥)"
echo "2. PINECONE_API_KEY (Pinecone向量数据库API密钥)" 